<?php
class Jbarang extends CI_Controller {

    public function __construct(){
		parent::__construct();
		$this->load->model('jbarang_model');
		$this->authlogin->chkLoggedin($this->session->userdata("usr_login"));
	}
	
	function index(){
		$data["judul_tabel"] = "Data Jenis Barang";
		$data["modul"] = "jbarang";
		$data["jbarang"] = $this->jbarang_model->get_data();
		$data["tabel"] = $this->load->view("master/jbarang/v_tabel_jbarang",$data,true);
		show("master/v_list_data", $data);
	}
	
	function add(){
		$data["judul_tabel"] = "Tambah Data Jenis Barang";
		$data["mode"] = "add";
		show("master/jbarang/v_jbarang", $data);
	}
	
	function edit($kd){
		$data["judul_tabel"] = "Edit Data Barang";
		$data["mode"] = "edit";
		$data["jbarang"] = $this->jbarang_model->get_data_row($kd);
		show("master/jbarang/v_jbarang", $data);
	}
	
	function del($kd){
		if($this->jbarang_model->delete_entry($kd)){
			$this->session->set_flashdata('alert_form', 'msgBerhasil();');
		}else{
			$this->session->set_flashdata('alert_form', 'msgGagal();');
		}
		redirect(base_url()."jbarang");
	}
	
	function save($mode){
		if($mode=="add"){
			if($this->jbarang_model->insert_entry()){
				$this->session->set_flashdata('alert_form', 'msgBerhasil();');
			}else{
				$this->session->set_flashdata('alert_form', 'msgGagal();');
			}
		}else{
			if($this->jbarang_model->update_entry($this->input->post("kd_jbarang"))){
				$this->session->set_flashdata('alert_form', 'msgBerhasil();');
			}else{
				$this->session->set_flashdata('alert_form', 'msgGagal();');
			}
		}
		redirect(base_url()."jbarang/edit/".$this->input->post("kd_jbarang"));
	}
}
